<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_jibifee/model')->方法名();
*/
namespace jy_jibifee;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function upinfee($mid=0){
		$mid=$mid?:$_SESSION['uid'];
		if(!$this->setting['inopen']){
			return false;
		}
		$isin=pdo_get('jy_jibifee_feelog',array('mid'=>$mid,'merchid'=>$_SESSION['onemerchid'],'type'=>3),'id');
		if(!$isin['id']){
			$infee1=$this->setting['infee1'];
			if($infee1>0){
					$feedata=array(
							'uniacid'=>$_SESSION['uniacid'],
							'mid'=>$mid,
							'merchid'=>$_SESSION['onemerchid'],
							'fee'=>$infee1,
							'createtime'=>TIMESTAMP,
							'type'=>3,
					);
					$this->insert('feelog',$feedata);
					if($_SESSION['onemerchid']){
						model('jy_merch/member')->member_credit($_SESSION['onemerchid'],$mid,'credit1',$infee1,true,'jy_jibifee','首次访问商城奖励');
					}else{
						cfc('core')->member_credit($mid,'credit1',$infee1,true,'jy_jibifee',$remark='首次访问商城奖励');
					}
			}
		}
		$isin=pdo_get('jy_jibifee_feelog',array('mid'=>$mid,'merchid'=>$_SESSION['onemerchid'],'type'=>4),'id');
		if(!$isin['id']){
			$infee3=$this->setting['infee3'];
			if($infee3>0){
					$feedata=array(
							'uniacid'=>$_SESSION['uniacid'],
							'mid'=>$mid,
							'merchid'=>$_SESSION['onemerchid'],
							'fee'=>$infee3,
							'createtime'=>TIMESTAMP,
							'type'=>4,
					);
					$this->insert('feelog',$feedata);
					if($_SESSION['onemerchid']){
						model('jy_merch/member')->member_credit($_SESSION['onemerchid'],$mid,'credit3',$infee3,true,'jy_jibifee','首次访问商城奖励');
					}else{
						cfc('core')->member_credit($mid,'credit3',$infee3,true,'jy_jibifee',$remark='首次访问商城奖励');
					}
			}
		}
		if($infee1 || $infee3){
			$res=array(
				'infee1'=>$infee1,
				'infee3'=>$infee3,
			);
			return $res;
		}else{
			return false;
		}
	}
	public function upfee($mid=0){
		$mid=$mid?:$_SESSION['uid'];
		if(!$this->setting['open']){
			return false;
		}
		if($_SESSION['onemerchid']){
			$fromuser=pdo_getcolumn('jy_merch_member',array('merchid'=>$_SESSION['onemerchid'],'mid'=>$mid),'fromuser');
		}else{
			$fromuser=pdo_getcolumn('core_members',array('merchid'=>$_SESSION['onemerchid'],'id'=>$mid),'fromuser');
		}
		if($fromuser){
			$isyao=pdo_get('jy_jibifee_feelog',array('merchid'=>$_SESSION['onemerchid'],'yaomid'=>$mid,'type'=>0),'id');
			$fee1=$this->setting['fee1'];
			if(!$isyao['id'] && $fee1>0){
					$feedata=array(
							'uniacid'=>$_SESSION['uniacid'],
							'mid'=>$fromuser,
							'yaomid'=>$mid,
							'merchid'=>$_SESSION['onemerchid'],
							'fee'=>$fee1,
							'createtime'=>TIMESTAMP,
							'type'=>0,
					);
					$this->insert('feelog',$feedata);
					if($_SESSION['onemerchid']){
						model('jy_merch/member')->member_credit($_SESSION['onemerchid'],$fromuser,'credit1',$fee1,true,'jy_jibifee','邀请奖励');
					}else{
						cfc('core')->member_credit($fromuser,'credit1',$fee1,true,'jy_jibifee',$remark='邀请奖励');
					}
			}
			$isyao=pdo_get('jy_jibifee_feelog',array('merchid'=>$_SESSION['onemerchid'],'yaomid'=>$mid,'type'=>0),'id');
			$fee3=$this->setting['fee3'];
			if(!$isyao['id'] && $fee3>0){
					$feedata=array(
							'uniacid'=>$_SESSION['uniacid'],
							'mid'=>$fromuser,
							'yaomid'=>$mid,
							'merchid'=>$_SESSION['onemerchid'],
							'fee'=>$fee3,
							'createtime'=>TIMESTAMP,
							'type'=>1,
					);
					$this->insert('feelog',$feedata);
					if($_SESSION['onemerchid']){
						model('jy_merch/member')->member_credit($_SESSION['onemerchid'],$fromuser,'credit3',$fee3,true,'jy_jibifee','邀请奖励');
					}else{
						cfc('core')->member_credit($fromuser,'credit3',$fee3,true,'jy_jibifee',$remark='邀请奖励');
					}
			}
		}
		return true;
	}
}
?>